<?php

/**
 * Cookie Class
 * @author ReGeDa
 */
class Cookie extends Plugin_Object {

	/**
	 * Get persistant plugin state
	 * @override
	 * @return boolean
	 */
	public function is_persistant() {
		return TRUE;
	}

	/**
	 * Set cookie value
	 * @param string $name
	 * @param mixed $value
	 * @param integer $expire
	 * @param string $domain
	 * @param string $path
	 */
	public function set($name, $value, $expire = 0, $domain = '', $path = '/') {

		// calculate expire time
		if (is_null($expire))
			$expire = time() - 63072000; // 2 years
		else if ($expire > 0)
			$expire = time() + $expire;

		// send to browser
		setcookie($name, $value, $expire, $path, $domain, 0);
	}

	/**
	 * Get cookie value
	 * @param string $name
	 * @param boolean $xss_clean
	 * @return mixed
	 */
	public function get($name, $xss_clean = FALSE) {
		return platcode()->plugins->import('Input')->cookie($name, $xss_clean);
	}

	/**
	 * Delete a cookie
	 * @param string|array $var
	 * @param string $domain
	 * @param string $path
	 */
	public function delete($var, $domain = '', $path = '/') {
		if (is_array($var)) {
			// multiple delete
			foreach ($var as $name)
				$this->delete($name, $domain, $path);
		}
		else
			$this->set($var, '', NULL, $domain, $path);
	}
}

// end of file